package com.xintoucloud.pbs.model;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ReadExcel {

	public static void main(String[] args) throws IOException {
		
		//File file = new File("C:/Users.xlsx");
		InputStream stream = new FileInputStream("C:/用户数据表.xml");
 
	    XSSFWorkbook xssfWorkbook = new XSSFWorkbook(stream);
	    XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
 
	    int rowstart = xssfSheet.getFirstRowNum();
	    int rowEnd = xssfSheet.getLastRowNum();
	    for(int i=rowstart;i<=rowEnd;i++)
	    {
	        XSSFRow row = xssfSheet.getRow(i);
	        if(null == row) continue;
	        int cellStart = row.getFirstCellNum();
	        int cellEnd = row.getLastCellNum();
 
	        for(int k=cellStart;k<=cellEnd;k++)
	        {
	            XSSFCell cell = row.getCell(k);
	            if(null==cell) continue;
 
 
	            switch (cell.getCellType())
	            {
	                case HSSFCell.CELL_TYPE_NUMERIC: // 数字
	                    System.out.print(cell.getNumericCellValue()
	                            + "\t");
	                    break;
	                case HSSFCell.CELL_TYPE_STRING: // 字符串
	                    System.out.print(cell.getStringCellValue()
	                            + "\t");
	                    break;
	                case HSSFCell.CELL_TYPE_BOOLEAN: // Boolean
	                    System.out.println(cell.getBooleanCellValue()
	                            + "\t");
	                    break;
	                case HSSFCell.CELL_TYPE_FORMULA: // 公式
	                    System.out.print(cell.getCellFormula() + "\t");
	                    break;
	                case HSSFCell.CELL_TYPE_BLANK: // 空值
	                    System.out.println(" ");
	                    break;
	                case HSSFCell.CELL_TYPE_ERROR: // 故障
	                    System.out.println(" ");
	                    break;
	                default:
	                    System.out.print("未知类型   ");
	                    break;
	            }
 
	        }
	        System.out.print("\n");
	    }
	}
}
 
 
